package com.yhj.handler;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
 * @author yaohj
 * @date 2024年11月21日 16:09
 */
@Aspect
@Component
@Validated
public class ValidationAspect {

    @Pointcut("within(@org.springframework.stereotype.Controller *) || " +
            "within(@org.springframework.web.bind.annotation.RestController *)")
    public void controllerPointcut() {
        // Pointcut definition here
    }

    @Around("controllerPointcut()")
    public Object validate(ProceedingJoinPoint joinPoint) throws Throwable {
        // Before method execution logic (if any)
        //执行目标方法
        Object result = joinPoint.proceed();
        // After method execution logic (if any)
        return result;
    }
}
